<template>
	<div>
		<HomeHeader></HomeHeader>
		<HomeLeft :cur="4"></HomeLeft>
		<div id="main">
			<div id="web_con" v-if="isedit">
				<div class="web_wp">
					<div class="web_location">
						<div class="here_area">
							<strong>当前位置：</strong>收益设置
						</div>
						<!-- <div class="here_btn">
							<a href="javascript:history.back()" class="web_btn btn_add"><em
									class="iconfont icon-shdcfanhui"></em>返回</a>
						</div> -->
					</div>

					<div class="tabTitle">
						<ul class="clearfix">
							<li :class="type==1?'cur':''" @click="type=1"><a href="javascript:;">会员收益设置</a></li>
							<li :class="type==2?'cur':''" @click="type=2"><a href="javascript:;">商户收益设置</a></li>
						</ul>
						<div class="tabCont" v-if="type==1">
							<div class="cont">
								<table class="dataTable">
									<!-- <tr>
										<td class="ltd">存入金额</td>
										<td class="rtd">
											<el-tag v-for="(tag,i) in tags" :key="tag.name" closable :type="tag.type"
												@close="MoveMoney(i)">
												{{tag.name}}
											</el-tag>

											<el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue"
												ref="saveTagInput" size="small" @keyup.enter.native="handleInputConfirm"
												@blur="handleInputConfirm">
											</el-input>
											<el-button v-else class="button-new-tag" size="small" @click="showInput">+添加</el-button>

										</td>
									</tr> -->

									<tr>
										<td class="ltd">2000元年化收益率</td>
										<td class="rtd">
											<input type="number" class="input-text" v-model="min_rate">
										</td>
									</tr>
									<tr>
										<td class="ltd">1万元及以上年化收益率</td>
										<td class="rtd">
											<input type="number" class="input-text" v-model="max_rate">
										</td>
									</tr>
									<!-- <tr>
										<td class="ltd">积分赠送比例</td>
										<td class="rtd">
											<input type="number" class="input-text" v-model="integral_rate">
										</td>
									</tr> -->

									<!-- <tr>
										<td class="ltd">期限</td>
										<td class="rtd">
											<select class="select">
												<option value="">请选择</option>
												<option>1个月</option>
												<option>3个月</option>
												<option>半年</option>
												<option>一年</option>
											</select>
										</td>
									</tr> -->
								</table>
							</div>
						</div>

						<div class="tabCont" v-if="type==2">
							<div class="cont">
								<table class="dataTable">
									<tr>
										<td class="ltd">商户自存收益率</td>
										<td class="rtd">
											<input type="number" class="input-text" v-model="merchant_rate">
										</td>
									</tr>
									<tr>
										<td class="ltd">会员管理收益率</td>
										<td class="rtd">
											<input type="number" class="input-text" v-model="member_rate">
										</td>
									</tr>
								</table>
							</div>
						</div>
						<div>
							<div class="contBtn">
								<table class="dataTable">
									<tfoot>
										<tr>
											<td class="ltd"></td>
											<td class="rtd">
												<a href="javascript:;" class="web_btn btn_add" @click="SubMit()">
													<em class="iconfont icon-shdcbaocun"></em>保存
												</a>
											</td>
										</tr>
									</tfoot>
								</table>
							</div>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
</template>

<script>
	import HomeHeader from '../components/Header.vue';
	import HomeLeft from '../components/Left.vue';
	import PicUp from '../components/PicUp.vue'
	export default {
		components: {
			HomeHeader,
			HomeLeft,
			PicUp
		},
		data() {
			return {
				info: [],
				isedit: false,
				type: 1,
				min_rate: 0,
				max_rate: 0,
				integral_rate: 0,
				merchant_rate: 0,
				member_rate: 0,
			}
		},
		onLoad(e) {
			let that = this;
			that.GetDeta();
		},
		methods: {
			GetDeta: function(id) {
				let that = this;
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				that.common.http('GET', 'config', '', function(res) {
					uni.hideLoading();
					that.min_rate = that.getVByName(res.data, 'min_rate');
					that.max_rate = that.getVByName(res.data, 'max_rate');
					that.integral_rate = that.getVByName(res.data, 'integral_rate');
					that.merchant_rate = that.getVByName(res.data, 'merchant_rate');
					that.member_rate = that.getVByName(res.data, 'member_rate');
					that.isedit = true;
				});
			},

			getVByName: function(arr, key) {
				const target = arr.find(item => item.key == key);
				return target ? target.value : null;
			},




			MoveMoney: function(e) {
				console.log(e)
			},

			showInput() {
				this.inputVisible = true;
				this.$nextTick(_ => {
					this.$refs.saveTagInput.$refs.input.focus();
				});
			},

			handleInputConfirm() {
				let inputValue = this.inputValue;
				if (inputValue) {
					this.dynamicTags.push(inputValue);
				}
				this.inputVisible = false;
				this.inputValue = '';
			},

			//保存
			SubMit: function() {
				let that = this;
				if (that.min_rate <= 0||that.max_rate<=0||that.integral_rate<=0||that.merchant_rate<=0||that.member_rate<=0) {
					uni.showToast({
						icon: 'none',
						title: '参数必须大于0',
						duration: 2000
					});	
					
				}else {
					let _data = {
						min_rate:that.min_rate,
						max_rate:that.max_rate,
						integral_rate:that.integral_rate,
						merchant_rate:that.merchant_rate,
						member_rate:that.member_rate	
					};
					that.common.http('POST', 'config', _data, function(res) {
						uni.hideLoading();
						uni.showToast({
							icon: 'none',
							title: '修改成功',
							duration: 2000
						});
						setTimeout(function() {
							that.GetDeta();
						}, 1500);
					});
					
				}
			},

			navigateBack() {
				// #ifdef H5
				const pages = getCurrentPages()
				if (pages.length > 1) {
					uni.navigateBack(1)
					return;
				}
				//使用vue-router返回上一级
				let a = this.$router.go(-1)
				if (a == undefined) {}
				return;
				// #endif
				uni.navigateBack();
			},

		}
	}
</script>

<style scoped>
	.el-tag+.el-tag {
		margin-left: 10px;
	}

	.button-new-tag {
		margin-left: 10px;
		height: 32px;
		line-height: 30px;
		padding-top: 0;
		padding-bottom: 0;
	}

	.input-new-tag {
		width: 90px;
		margin-left: 10px;
		vertical-align: bottom;
	}
</style>